<?php

include "../../app/dao/order.php";

class Order_Dao {
	
	var $orderdetail = array();
	var $order_id;
	var $query;
	var $error;
    var $db;
	
	public function __construct(Database $db){
        $this->db = $db;
    }

	function get_orderdetail($id=null,$posisi=null, $batas=null, $store=null){
	
		$this->db->connect->connect();
		
		if($this->db->table_Exists('order_detail')){
		
			if($id!=null AND $posisi==null AND $batas==null AND $store!=null){
			
				$this->query = "SELECT
								*
								FROM 
								order_detail 
								WHERE 
								order_id='".$id."'
								AND
								store='".$store."'
								";
			}else if($id!=null AND !is_null($posisi) AND !is_null($batas)){
                $this->query = "SELECT
								*
								FROM
								order_detail 
								WHERE 
								order_id = '".$id."'
							
								
								LIMIT $posisi,$batas";
            }else if(!is_null($posisi) AND !is_null($batas)){
                $this->query = "SELECT
								*
								FROM
								order_detail                
							
								LIMIT $posisi,$batas";
            }else{
                $this->query = "SELECT
								*
								FROM
								order_detail       
								";
            }
			//print_r($this->query);			
			$result = mysql_query($this->query);
			
			if($result){
				
				while($r=mysql_fetch_array($result)){
				
					$orderdetail = new Order();
					
					$orderdetail->order_id = $r['order_id'];
					$orderdetail->product = $r['product'];
					$orderdetail->store = $r['store'];
					$orderdetail->price = $r['price'];
					$orderdetail->jumlah= $r['jumlah'];
					$orderdetail->total = $r['total'];
					
					$this->orderdetail[] = $orderdetail;
					
				}
				
				$this->db->connect->disconnect();
				return $this->orderdetail;
				
			}else{
				
				$this->error = 'data tidak ditemukan';
				return $this->error;
				
			}
		}else{
			
			$this->error = 'data tidak ditemukan';
			return $this->error;
			
		}
	}
	
	function del($id){
	
		$this->db->connect->connect();
		
		if($this->db->table_Exists('order_detail')){
		
			if($id!=null){
			
				$this->query = "DELETE 
								FROM 
								order_detail 
								WHERE 
								order_id='".$id."'
								";
			
			}else{
			
				$this->error = 'data tidak ditemukan';
				return $this->error;
				
			}
			
			mysql_query($this->query);
            $this->db->connect->disconnect();
		
		}else{
		
			$this->error = 'data tidak ditemukan';
			return $this->error;
			
		}
	}
	
}
?>